﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace FileEncoding
{
    public partial class Form2 : Form
    {
        private string[] typeArr = new string[] { ".cs", ".aspx", "*.csproj", ".cpp", ".cxx", ".c", ".h", ".rc", ".tlh", ".tli", ".java", ".asp", ".php", ".php3", ".jsp", ".htm", ".html", ".vb", ".bas", ".frm", ".ctl", ".cls", ".pas", ".dfm", ".sql", ".txt", ".bat" };
        //private string[] typeArr = new string[] { ".ini", ".lua", ".sql", ".Ani", ".txt", ".cs", ".aspx", ".csproj", ".c", ".cpp" };
        public List<string> extensions = new List<string>();

        public Form2()
        {
            InitializeComponent();
            InitComponentValue();
        }

        private void InitComponentValue()
        {
            // 初始化checkedListBox选项
            for (int i = 0; i < typeArr.Length; i++)
            {
                clbTypes.Items.Add(typeArr[i]);
            }

            // 设置默认值
            clbTypes.SetItemChecked(0, true);
            clbTypes.SetItemChecked(1, true);
            //clbTypes.SetItemChecked(2, true);
            //clbTypes.SetItemChecked(3, true);
            //clbTypes.SetItemChecked(4, true);
            //clbTypes.SetItemChecked(5, true);
            RefreshTypes();
        }

        // 确定按钮点击
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            // 添加选择类型
            RefreshTypes();
            // 刷新Form1中的已选择类型
            RefreshTypesLabel();

            // 关闭窗口
            this.Close();
        }

        private void RefreshTypes()
        {
            extensions.Clear();
            for (int i = 0; i < clbTypes.Items.Count; i++)
            {
                if (clbTypes.GetItemChecked(i))
                {
                    Console.WriteLine(clbTypes.Items[i].ToString());
                    extensions.Add(clbTypes.Items[i].ToString());
                }
            }
        }

        public void RefreshTypesLabel()
        {
            string choosedStr = "";
            for (int i = 0; i < extensions.Count; i++)
            {
                choosedStr += extensions[i] + "; ";
            }
            Form1.OnChooseEnd(choosedStr);
        }
    }
}
